package com.huawei.hms.framework.network.grs.c;

import android.content.res.AssetManager;
import android.text.TextUtils;
import com.huawei.hms.framework.common.Logger;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import o.avb;
import o.fc.c;

public class d {
    private static final String a = d.class.getSimpleName();
    private static int ˊ = 0;
    private static int ˏ = 1;

    public static String a(String str) {
        Throwable th;
        InputStream inputStream = null;
        Object obj = null;
        try {
            int i = ˊ + 77;
            try {
                String str2;
                int i2;
                ˏ = i % DnsConfig.MAX_CACHE_ENTRIES;
                if (i % 2 == 0) {
                    str2 = "";
                } else {
                    str2 = "";
                }
                if (!TextUtils.isEmpty(str)) {
                    i2 = 1;
                }
                switch (obj) {
                    case null:
                        i2 = ˏ + 61;
                        ˊ = i2 % DnsConfig.MAX_CACHE_ENTRIES;
                        switch (i2 % 2 != 0 ? 68 : 62) {
                            case c.ꜞॱ /*68*/:
                                Logger.w(a, "getConfigContent fileName is null.");
                                i2 = 6 / 0;
                                return str2;
                            default:
                                Logger.w(a, "getConfigContent fileName is null.");
                                return str2;
                        }
                    default:
                        OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                        InputStream inputStream2;
                        try {
                            AssetManager assets = b.a().getAssets();
                            inputStream2 = (InputStream) ((Class) avb.ˏ(5, 0, '㮃')).getMethod("ˏ", new Class[]{AssetManager.class, String.class}).invoke(null, new Object[]{str, assets});
                            try {
                                byte[] bArr = new byte[8192];
                                int i3 = ˊ + 105;
                                ˏ = i3 % DnsConfig.MAX_CACHE_ENTRIES;
                                if (i3 % 2 == 0) {
                                    while (true) {
                                    }
                                }
                                i3 = inputStream2.read(bArr);
                                if (i3 != -1) {
                                    byteArrayOutputStream.write(bArr, 0, i3);
                                } else {
                                    byteArrayOutputStream.flush();
                                    String str3 = new String(byteArrayOutputStream.toByteArray(), "UTF-8");
                                    a(byteArrayOutputStream);
                                    a(inputStream2);
                                    return str3;
                                }
                            } catch (IOException e) {
                            }
                        } catch (IOException e2) {
                            inputStream2 = null;
                            try {
                                Logger.w(a, "local config file is not exist.");
                                a(byteArrayOutputStream);
                                a(inputStream2);
                                return str2;
                            } catch (Throwable th2) {
                                inputStream = inputStream2;
                                th = th2;
                                a(byteArrayOutputStream);
                                a(inputStream);
                                throw th;
                            }
                        } catch (Throwable th3) {
                            th = th3;
                            a(byteArrayOutputStream);
                            a(inputStream);
                            throw th;
                        }
                }
            } catch (Exception e3) {
                throw e3;
            }
        } catch (Exception e32) {
            throw e32;
        }
    }

    public static void a(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (Throwable e) {
                Logger.e(a, "closeQuietly IOException", e);
            }
        }
    }

    public static void a(InputStream inputStream) {
        a((Closeable) inputStream);
    }

    public static void a(OutputStream outputStream) {
        a((Closeable) outputStream);
    }
}
